package sol.leetcode;

import java.util.Arrays;

/**
 * Set Matrix Zeroes
 */
public class Issue073 {
    public void setZeroes(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] ms = new int[m];
        int[] ns = new int[n];

        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                if (matrix[i][j] == 0) {
                    ms[i] = 1;
                    ns[j] = 1;
                }
            }
        }
        for (int i = 0; i < m; ++i)
            if (ms[i] == 1)
                for (int j = 0; j < n; ++j)
                    matrix[i][j] = 0;
        for (int j = 0; j < n; ++j)
            if (ns[j] == 1)
                for (int i = 0; i < m; ++i)
                    matrix[i][j] = 0;
    }

    public static void main(String[] args) {
        int[][] matrix = {{1, 2, 0}, {1, 2, 1}, {1, 0, 2}};
        new Issue073().setZeroes(matrix);
        for (int[] line : matrix)
            System.out.println(Arrays.toString(line));
    }
}
